
/*给你一个下标从 0 开始的字符串数组 words 和两个整数：left 和 right 。
如果字符串以元音字母开头并以元音字母结尾，那么该字符串就是一个 元音字符串 ，其中元音字母是 'a'、'e'、'i'、'o'、'u' 。
返回 words[i] 是元音字符串的数目，其中 i 在闭区间 [left, right] 内。*/

import java.util.Scanner;

public class VowelStrings {
    private static final String vowels = "aeiouAEIOU";

    public static int vowelStrings(String[] words, int left, int right) {
        int count = 0;
        for (int i = left; i <= right; i++) {
            String word = words[i];
            if(word.length() == 0) {
                continue;
            }
            char first = word.charAt(0);
            char last = word.charAt(word.length() - 1);
            if(vowels.indexOf(first) != -1 && vowels.indexOf(last) != -1) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入字符串数组（用空格分隔）: ");
        String input = scanner.nextLine();
        String[] words = input.split(" ");

        System.out.print("请输入left: ");
        int left = scanner.nextInt();
        System.out.print("请输入right: ");
        int right = scanner.nextInt();

        int result = vowelStrings(words, left, right);
        System.out.println("元音字符串的数目: " + result);

        scanner.close();

    }
}
